package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

/**
 * @description: 星期枚举
 * @Author: hongxiao
 * @date: 2019-04-24 14:45
 * @since v1.0
 */
@Getter
public enum WeekEnum {
    /**
     * 星期枚举
     */
    MONDAY(Calendar.MONDAY, "monday", "enum.week.name.monday"),
    TUESDAY(Calendar.TUESDAY, "tuesday", "enum.week.name.tuesday"),
    WEDNESDAY(Calendar.WEDNESDAY, "wednesday", "enum.week.name.wednesday"),
    THURSDAY(Calendar.THURSDAY, "thursday", "enum.week.name.thursday"),
    FRIDAY(Calendar.FRIDAY, "friday", "enum.week.name.friday"),
    SATURDAY(Calendar.SATURDAY, "saturday", "enum.week.name.saturday"),
    SUNDAY(Calendar.SUNDAY, "sunday", "enum.week.name.sunday"),
    ;
    /**
     * 标识值
     */
    private Integer code;
    /**
     * 英文名称
     */
    private String alias;
    /**
     * 中文名称
     */
    private String name;

    WeekEnum(Integer code, String alias, String name) {
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    public static WeekEnum getByCode(Integer code) {
        for(WeekEnum weekEnum : values()) {
            if(Objects.equals(weekEnum.getCode(), code)) {
                return weekEnum;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return List<WeekEnum>
     */
    public static List<WeekEnum> getAllEnum() {
        List<WeekEnum> list = new ArrayList<>();
        for (WeekEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
